package com.yiwenup.leetcode.top_interview_150;

/**
 * 文件描述
 *
 * @Project struct-algorithm
 * @Package com.yiwenup.leetcode.top_interview_150
 * @Author yiwenup
 * @Date 2024-12-09 19:13:08
 * @Description https://leetcode.cn/problems/valid-palindrome/description/?envType=study-plan-v2&envId=top-interview-150
 */
public class No0125 {
    public boolean isPalindrome(String s) {
        int left = 0;
        int right = s.length()-1;

        while(left < right) {
            char lc = s.charAt(left);
            char rc = s.charAt(right);
            if(!Character.isLetterOrDigit(lc)) {
                left++;
                continue;
            }
            if(!Character.isLetterOrDigit(rc)) {
                right--;
                continue;
            }
            if(Character.toLowerCase(lc) == Character.toLowerCase(rc)) {
                left++;
                right--;
            } else {
                return false;
            }
        }

        return true;
    }
}
